package org.adoxx.pn.simulation.handlers.impl;

import org.adoxx.pn.PetriNet;
import org.adoxx.pn.PetriNet.PL;
import org.adoxx.pn.PetriNet.TR;
import org.adoxx.pn.simulation.handlers.SimulationListenerI;

public class CostCalculator implements SimulationListenerI {
    private double cost = 0;
    
    @Override
    public void simulationStarted(PetriNet petriNet) throws Exception{
        cost = 0;
    }

    @Override
    public void transitionFiredEvent(TR transitionFired) throws Exception { //FIXME: arc weight
        for(PL place: transitionFired.previousList)
            if(place.additionalInfoList.containsKey("cost"))
                cost += Double.parseDouble(place.additionalInfoList.get("cost"));
    }

    public double getCost(){
        return cost;
    }

    @Override
    public void simulationEnded(PetriNet petriNet) throws Exception{
        //Nothing to do here
    }
}

